package com.example.rabbitdemo.exchanger.direct;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectExchangeConfig {

    // 声明一个持久化的直连交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("exchange.direct", true, false);
    }

    // 声明队列 - 用于处理订单消息
    @Bean
    public Queue orderQueue() {
        return new Queue("queue.order", true);
    }

    // 声明队列 - 用于处理支付消息
    @Bean
    public Queue paymentQueue() {
        return new Queue("queue.payment", true);
    }

    // 将订单队列绑定到交换机，并指定路由键为 "order"
    @Bean
    public Binding orderBinding(DirectExchange directExchange, Queue orderQueue) {
        return BindingBuilder.bind(orderQueue).to(directExchange).with("order");
    }

    // 将支付队列绑定到交换机，并指定路由键为 "payment"
    @Bean
    public Binding paymentBinding(DirectExchange directExchange, Queue paymentQueue) {
        return BindingBuilder.bind(paymentQueue).to(directExchange).with("payment");
    }
}